#ifndef WIDGETEDITNODE_H
#define WIDGETEDITNODE_H

#include <QWidget>
#include "../entity/EntitySceneNode.h"

namespace Ui {
class WidgetEditNode;
}

class WidgetEditNode : public QWidget
{
    Q_OBJECT

public:
    explicit WidgetEditNode(QWidget *parent = nullptr);
    ~WidgetEditNode();

signals:
    void sig_editApply(EntitySceneNode* node);

public slots:
    void newNode(const QString& type, EntitySceneNode* parent);
    void editNode(const QString& name);

private:
    void reset(const EntitySceneNode* node, const QString& type, bool clearWidgets = true);
    void setupInput(const QString& type);
    bool updateAttribute(EntitySceneNode* node);
    void fromAttribute(EntitySceneNode* node);
    void toAttribute(EntitySceneNode* node, QStringList& attribList);
    void splitAttribute(const QString& str, QList<QPair<QString, QString>>& result);

    void addRowCheck(int row, const QString& title, const QString& name, const QString& defValue = "false");
    void addRowColor(int row, const QString& title, const QString& name, const QString& defValue = "#FFFFFFFF");
    void addRowCombo(int row, const QString& title, const QString& name, const QStringList& items, std::function<void(int)> onChange, const QString& type = "string", const QString& defValue = "");
    void addRowFile(int row, const QString& title, const QString& name, const QString& filter, bool allowEmpty = false, const QString& defValue = "");
    void addRowText(int row, const QString& title, const QString& name, const QString& type, const QString& defValue = "");

private:
    Ui::WidgetEditNode *ui;
    QMap<QString, QString> _attributeMapInit;
};

#endif // WIDGETEDITNODE_H
